package com.hong.spring.beanfactory;


import com.hong.spring.common.entity.User;
import com.hong.spring.common.entity.User2;
import com.hong.spring.common.service.MessageService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import java.util.Arrays;

/**
 *
 * 功能描述:beanFactory测试
 *
 * @param:
 * @return:
 * @auther: csh
 * @date: 2020/7/8 18:36
 */
public class BeanFactoryTest {
    public static void main(String[] args) {
        //从类路径的xm文件载入上下文定义的信息
        ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/beanfactory/applicationfile-setter.xml");
        System.out.println("context 已启动!");
        User user = context.getBean(User.class,"user.properties");
        System.out.println("user信息："+user.toString()+":内存"+System.identityHashCode(user));
        System.out.println("是否包含："+context.containsBean("user.properties"));
        System.out.println("是否单例："+context.isSingleton("user.properties"));
        System.out.println("是否一致!"+context.isTypeMatch("user.properties",User.class));
        Class <?> user1 = context.getType("user.properties");
        System.out.println(user1.toString());
        System.out.println(Arrays.asList(context.getAliases("user.properties")).toString());
        //从文件系统的xml文件载入上下文定义信息
        ApplicationContext context2 = new FileSystemXmlApplicationContext("src/main/resources/beanfactory/applicationfile-required.xml");
        User user2 = context2.getBean(User.class,"user.properties");
        System.out.println("user2信息:"+user2.toString()+":内存"+System.identityHashCode(user2));

    }

}
